package gentle.controller;

import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.BaseController;
import gentle.entity.*;
import gentle.factory.PageFactory;
import gentle.service.CustomerForGoodsService;
import gentle.service.ICustomerAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author py
 * @Date 2019年4月19日23:15:54
 */
@Controller
@RequestMapping("/customerForGoods")
public class CustomerForGoodsController extends BaseController {
    @Autowired
    CustomerForGoodsService forGoodsService;
    /**
     * 兑换商品列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object testrInfoList(SearchPointRewordInfo info, HttpServletRequest request) {
        Page<PointRewordInfo> page = new PageFactory<PointRewordInfo>().defaultPage();
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<PointRewordInfo> list = forGoodsService.selectPageListByQueryGetMap(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = forGoodsService.selectPageListByQueryGetMap(page, info);
            }
            page.setTotal(forGoodsService.getQueryPagesMemberCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 统计查询
     */
    @RequestMapping(value = "/total", method = RequestMethod.GET)
    @ResponseBody
    public List<PointRewordInfo> PointRewordInfototal(String startCreateTime, String endCreateTime) throws Exception {
        return forGoodsService.PointRewordInfototal(startCreateTime, endCreateTime);
    }

}